package com.cn.tools;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.SimpleTagSupport;

public class ReferTag extends SimpleTagSupport {
	
	@Override
	public void doTag() throws JspException, IOException {
		
		PageContext jc=(PageContext)this.getJspContext();
		
		HttpServletRequest request=(HttpServletRequest) jc.getRequest();
		
		String str=request.getHeader("referer");
		HttpServletResponse response=(HttpServletResponse)jc.getResponse();
		
		if(str==null || !str.startsWith("http://localhost:8088/amazon")){
			//都可认为是倒链的
			//System.out.println("倒链");
			response.sendRedirect("/amazon/referer.jsp");
			return;
		}else{
			//System.out.println("没有倒链可以放行");
			return;
		}
	}
}
